#定义用户存款信息：
Userinformation = {"88888":{"password":"123456","deposit":100000},
                   "99999":{"password":"123456","deposit":2000},
                   "77777":{"password":"123456","deposit":10}}
#登录验证返回ok,msg,name
def login():
    name = input("请输入卡号：")
    if not name:
        print("用户卡号不能为空！")
    if name in Userinformation.keys():
        password = input("请输入密码：")
        if not password:
            print("密码不能为空！")
        if Userinformation [name]["password"] == password:
            return True,"登录成功",name
        return False,"用户名或密码错误",name
    return False,"用户名不存在",name

#返回余额
def query(name):
    return Userinformation[name]["deposit"]
#存款并返回余额
def save(name,num):
     Userinformation[name]["deposit"] += num
     return Userinformation[name]["deposit"]

#取款并返回余额
def take(name,num):
    if Userinformation[name]["deposit"] < num:
        return False
    Userinformation[name]["deposit"] -= num
    return Userinformation[name]["deposit"]

while 1:
    print(30 * "=")
    print("欢迎使用自助取款机")
    ok,msg,name = login()
    print(msg)
    #登录不成功，重新输入
    if not ok:
        continue
    while 1:
        print(30 * "=")
        print("1:查询余额：2：存款：3：取款：q:退去：")
        do = input("请输入操作编号：")
        if do == "1":
            deposit = query(name)
            print("查询成功，余额为{0}".format(deposit))
            continue
        elif do == "2":
            num = input("请输入存款数额：")
            deposit = save(name,int(num))
            print("存款成功，余额为{0}".format(deposit))
            continue
        elif do == "3":
            num = input("请输入取款数额：")
            deposit = take(name,int(num))
            if not deposit:
                print("余额不足")
            else:
                print("取款成功，余额为{0}".format(deposit))
                continue
        elif do == "q":
            break
        else:print("请重新输入卡号！")
